package com.yc.txx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.txx.entity.Car;
import com.yc.txx.mapper.CarMapper;
import com.yc.txx.mapper.ImageMapper;
import com.yc.txx.service.BizException;
import com.yc.txx.service.ICarService;
import com.yc.txx.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 天下行租车-车辆表-10 服务实现类
 * </p>
 *
 * @author xl
 * @since 2024-05-07
 */
@Service
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarService {

    @Autowired
    CarMapper carMapper;

    @Autowired
    ImageMapper imageMapper;


    @Override
    public void addCar(Car car) throws BizException{

        LambdaQueryWrapper<Car> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Car::getModel,car.getModel());
        lqw.eq(Car::getBrand,car.getBrand());
        lqw.eq(Car::getIntro,car.getIntro());

        if(count(lqw)>0){
            throw new BizException("该汽车已存在","intro");
        }

        carMapper.addCar(car);
        imageMapper.addImage(car.getId(),car.getImages());
    }
}
